# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=mcpp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.7.2.1
pkgrel=1
pkgdesc="Matsui's CPP implementation precisely conformed to standards (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://mcpp.sourceforge.net/"
msys2_repository_url="https://github.com/museoa/mcpp"
msys2_references=(
  "cpe: cpe:/a:mcpp_project:mcpp"
)
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libiconv")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/museoa/mcpp/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-aarch64.patch")
sha256sums=('ec6c2ead79b2334fccf56b8811256c4fccbbe2350e6a2e52dc83a1c7ad995af4'
            '9cd79569cccdd075b2c55e36e292d4c92a4e792c31c603d8e48890b6ac1b832f')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  apply_patch_with_msg \
    001-aarch64.patch
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  CFLAGS+=" -Wno-incompatible-pointer-types -Wno-discarded-qualifiers" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-mcpplib

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
